package jzc.mzxy.datebinding;

import android.databinding.BindingAdapter;
import android.databinding.DataBindingUtil;
import android.databinding.ObservableField;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import jzc.mzxy.datebinding.databinding.ActivityMainBinding;
import jzc.mzxy.datebinding.moder.NewPerson;
import jzc.mzxy.datebinding.moder.Person;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding= DataBindingUtil.setContentView(this,R.layout.activity_main);
//        setContentView(R.layout.activity_main);
        final Person person=new Person();
        person.setUrl("https://pic4.zhimg.com/v2-f2b0f3b7f319e4a91ae99b1f5273403b.jpg");
        person.setUrl1("https://pic4.zhimg.com/v2-f2b0f3b7f319e4a91ae99b1f5273403b.jpg");
        person.setAge("30");
        person.setName("臭傻逼");
        binding.setVariable(jzc.mzxy.datebinding.BR.person1,person);

        final ObservableField<String> string=new ObservableField<>();
        string.set("username");
        binding.setVariable(jzc.mzxy.datebinding.BR.username,string);

        final NewPerson newPerson=new NewPerson();
        newPerson.age.set("newPerson 的age");
        newPerson.name.set("newPerson 的name");
        binding.setVariable(jzc.mzxy.datebinding.BR.newperson,newPerson);
        binding.setVariable(jzc.mzxy.datebinding.BR.myclick,new Myclick());


//        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                person.setAge("40");
//                person.setName("丑不怪");
//                string.set("新的username");
//                newPerson.age.set("newPerson 新的age");
//                newPerson.name.set("newPerson 新的name");
//            }
//        });

    }
    @BindingAdapter("networkurl")
    public static void setImageUrl(ImageView imageUrl, String url){
        Log.i("networkurl","url"+url);
        Glide.with(imageUrl.getContext()).load(url).into(imageUrl);
    }

    public class Myclick{

        public void myclick1(View view){
            Log.i("Myclick","onclick");

        }
    }
}
